<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of User_Reponse
 *
 * @author fabrice
 */
class Model_User_Reponse extends PDO_Mysql{
    
    protected $_name = 'user_reponse';
    protected $_primary = 'id_reponse';

    /**
     * Recupere tout les questions par utilisateur
     * @return <array>
     */
    public function getReponseByUserQuestionId($id_user_question) {

        $sql = "SELECT * FROM " . $this->_name ." WHERE id_user_question=" . $id_user_question;
        $result = $this->pquery($sql);
        $row = $this->pfetchAll($result);
        return $row;
    }
    
    /**
     * Recupere tout les utilisateurs par questions
     * @return <array>
     */
    public function getReponseByFriendId($id_user_friend ) {

        $sql = 'SELECT * FROM ' . $this->_name . " WHERE id_user_friend =" . $id_user_friend ;
        $result = $this->pquery($sql);
        $row = $this->pfetch($result);
        return $row;
    }

    /**
     * Insert user_question
     * @param <int> $id_question
     * @param <int> $id_user
     * @return <bool> $row
     */
    public function setUserReponse($formData) {

        $sql = 'INSERT INTO ' . $this->_name . ' (id_reponse,id_user_question,id_user_friend,reponse)' .
                ' VALUES (:id_reponse,:id_user_question,:id_user_friend,:reponse)';
        $data = array(
            ':id_reponse' => NULL,
            ':id_user_question' => $formData['id_user'],
            ':id_user_friend' => $formData['id_user_friend'],
            ':reponse' => $formData['reponse']
        );
        $row = $this->pinsert($sql, $data, 'id_reponse');
        return $row;
    }
    
    public function getUserReponse($id_reponse){
        $sql = "SELECT * FROM " . $this->_name . " as A 
                LEFT JOIN user_question AS B ON B.id_user_question = A.id_user_question
                LEFT JOIN question AS C ON C.id_question = B.id_question
                LEFT JOIN USER AS D ON B.id_user = D.id_user
                WHERE id_reponse='" . $id_reponse . "'";
        
        $query = $this->query($sql);
        $result = $this->pfetch($query);
    }
}

?>